// pages/h.js
var nv = require("../../utils/request.js");
Page({

  /**s
   * 页面的初始数据
   */
  data: {
    isHideLoadMore: true,
    isHideLoadCount: true, //true不显示 false显示
    pageIdex: 1,
    userlist: [{
      "name": "Crab",
      "phone": "15566667777",
      "time": "2017-10-14"
    }, {
      "name": "Emily",
      "phone": "15566668888",
      "time": "2017-10-13"
    }, {
      "name": "Rachel",
      "phone": "15566669999",
      "time": "2017-10-10"
    }, {
      "name": "Crab2",
      "phone": "15566667777",
      "time": "2017-10-14"
    }, {
      "name": "Emily2",
      "phone": "15566668888",
      "time": "2017-10-13"
    }, {
      "name": "Rachel2",
      "phone": "15566669999",
      "time": "2017-10-10"
    }, {
      "name": "Crab3",
      "phone": "15566667777",
      "time": "2017-10-14"
    }, {
      "name": "Emily3",
      "phone": "15566668888",
      "time": "2017-10-13"
    }, {
      "name": "Rachel3",
      "phone": "15566669999",
      "time": "2017-10-10"
    }, {
      "name": "Rachel3",
      "phone": "15566669999",
      "time": "2017-10-10"
    }, {
      "name": "Rachel3",
      "phone": "15566669999",
      "time": "2017-10-10"
    }, {
      "name": "Rachel3",
      "phone": "15566669999",
      "time": "2017-10-10"
    }, {
      "name": "Rachel3",
      "phone": "15566669999",
      "time": "2017-10-10"
    }],
    nvList: [],

  },

  listitemClick: function(e) {
    //拿到点击的index下标
    var index = e.currentTarget.dataset.index;
    // var phone = this.data.userlist[index].phone;
    var nvurl = this.data.nvList[index].imgurl;
    wx.navigateTo({
      url: "../listiteminfo/listiteminfo?nvurl=" + nvurl,
    });
  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    var list = [];
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.setData({ //下拉时先隐藏上拉加载框
      isHideLoadMore: true,
    });
    //模拟加载
    setTimeout(function() {
      list.push({
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }, {
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }, {
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }, {
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }),
        that.setData({
          userlist: list,
        });
      // complete
      wx.hideNavigationBarLoading(); //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, 1000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var list = this.data.userlist;
    var that = this;
    var pageIdex = this.data.pageIdex;
    this.setData({
      isHideLoadMore: false,
    });
    if (parseInt(that.data.pageIdex) >= 3) {
      that.setData({
        pageIdex: pageIdex + 1,
        isHideLoadMore: true,
        isHideLoadCount: false,
      });
    } else {
      setTimeout(function() {
        list.push({
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }, {
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }, {
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        }, {
          "name": "tom",
          "phone": "1556de6668888",
          "time": "2017-10-13"
        });
        if (parseInt(that.data.pageIdex) < 3) {
          that.setData({
            pageIdex: pageIdex + 1,
            isHideLoadMore: false,
            userlist: list,
          });
        };
        // console.log(parseInt(that.data.pageIdex));

      }, 1000);
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    nv.nvRequest("", this.doSuccess, this.doFailed);
  },

  /**
   * 请求成功时
   */
  doSuccess: function(data) {
    this.setData({
      nvList: data
    });
  },

  /**
   * 请求失败时
   */
  doFailed: function() {
    console.log("请求失败")
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },


})